#!/bin/sh
# PCP QA Test No. 560
# #681487 error handling in pmdaproc.sh dialogs
#
# Copyright (c) 1995-2002 Silicon Graphics, Inc.  All Rights Reserved.
#

seq=`basename $0`
echo "QA output created by $seq"

# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check

[ -d $PCP_PMDAS_DIR/simple ] || _notrun "simple PMDA directory is not installed"

status=1	# failure is the default!
trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
$sudo rm -f $seq.full

# real QA test starts here
cd $PCP_PMDAS_DIR/simple

unset ROOT MAKEFLAGS

$sudo $PCP_MAKE_PROG clobber >>$here/$seq.full 2>&1
$sudo $PCP_MAKE_PROG >>$here/$seq.full 2>&1

_filter_make()
{
    sed \
	-e '/In function .vpmprintf./d' \
	-e '/warning: the use of .tempnam./d' \
	-e '/make: Nothing to be done/d'
}

# see note below on bind: Address already in use issue
#
port=`_get_port tcp 12078 12127`
if [ -z "$port" ]
then
    echo "Arrgh ... no free TCP port in the range 12078 ... 12127"
    exit
fi
echo "port=$port" >>$here/$seq.full
cat <<End-of-File | $sudo ./Install -e >$tmp.out 2>&1
foo
daemon
foo
socket
foo
Unix

Internet
$port
End-of-File

tee -a $here/$seq.full <$tmp.out \
| sed \
    -e "s/ $port\$/ PORT/" \
    -e 's/or perl //g' \
    -e 's/or python //g' \
    -e 's/daemon or dso,/"daemon" or "dso",/g' \
| _filter_pmda_install \
| _filter_make

echo "in \$PCP_PMCDCONF_PATH ..."
sed -n <$PCP_PMCDCONF_PATH \
    -e '/^simple/{
s;/private/;/;
s;'"$PCP_PMDAS_DIR"';$PCP_PMDAS_DIR;
s/$/ /
s/\([ 	]\)'"$port"'\([ 	]\)/\1PORT\2/g
s/ $//
p
}'

if [ -f "$PCP_LOG_DIR/pmcd/simple.log" ]
then
    cat "$PCP_LOG_DIR/pmcd/simple.log" >>$here/$seq.full
else
    echo "$PCP_LOG_DIR/pmcd/simple.log: missing?"
fi
pminfo -f simple pmcd.agent.status >>$here/$seq.full

$sudo ./Remove

# need to be sure these back-to-back installs use a different
# port ... otherwise the second install risks smacking into a
# "bind: Address already in use" issue if the previous PMDA
# process has not cleaned up ... this is why the first install
# uses a port in the range starting at 1000+2078, so the second
# install below can use the default 2078 port
#

echo
if $sudo $PCP_MAKE_PROG >$tmp.tmp 2>$tmp.err
then
    cat $tmp.err | _filter_make
else
    cat $tmp.tmp
    echo "make prior to Install failed!"
fi
$sudo ./Install </dev/null >$tmp.out 2>&1
tee -a $here/$seq.full <$tmp.out \
| grep 'Check'

if [ -f "$PCP_LOG_DIR/pmcd/simple.log" ]
then
    cat "$PCP_LOG_DIR/pmcd/simple.log" >>$here/$seq.full
else
    echo "$PCP_LOG_DIR/pmcd/simple.log: missing?"
fi
pminfo -f simple pmcd.agent.status >>$here/$seq.full

# success, all done
status=0
exit
